xlv.obj.ajaxPane={
	extend:function(){
	},
	implement:function(){
		this.implement('xlv.imp.ajax');
	},
	pub:{
		loading:'/xlive/images/_loading.gif'
	},
	create:function(tag){
		var div=document.createElement((tag||'div'));
		div.setAttribute('xlvobject','xlv.obj.ajaxPane');
		return div;
	},
	properties:{
		paneURL:null,
		paneProperties:null,
		paneMethod:null,
		paneIn:'left-top',//left top right bottom, center
		onSite:'replace',//replace,append
		autoRequest:true
	},
	method:{
		initial:function(){
			Element.addClassName(this,'class_ajaxPane');
			var p=this.$P;
			if(p.autoRequest&&p.paneURL)this.request(p.paneURL,p.paneProperties,p.paneMethod);
			this.addEventHandler('xlv:dispose','xlv_dispose');
		},
		message:function(memo){
			if(memo.type=='active_changed'&&xlv.util.isDescendantOf(this,memo.to)){
				if(!this.$P.autoRequest && !this.$V.requested) {
					memo.cancel=true;
					var p=this.$P;
					this.request(p.paneURL,p.paneProperties,p.paneMethod);
				}
			}
		},
		xlv_dispose:function(event){
		},
		dispose:function(){
		},
		request:function(url,properties,method){
			var v=this.$V;
			v.loading=document.createElement('img');
			v.loading.setAttribute('src',xlv.obj.ajaxPane.pub.loading);
			var lt=xlv.desktop.viewportOffset(this);
			v.loading.style.position='absolute';
			v.loading.style.left=(lt[0])+'px';
			v.loading.style.top=(lt[1])+'px';
			v.loading.style.zIndex='1000';
			this.appendChild(v.loading);
			v.loaded=false;
			v.url=url;
			v.properties=properties;
			v.method=method;
			var options={};
			setTimeout(function(){this.ajax_request(v.url,options);}.bind(this),2);
			v.requested=true;
		},
		isLoading:function(){
			return this.$V.loading!=null;
		},
		isLoaded:function(){
			return this.$V.loaded===true;
		},
		loaded:function(){
			this.$V.loaded=true;
			var memo=xlv.sys.createMemoObject();
			memo.type='loaded';
			memo.src=this;
			memo.from=this.$V.url;
			memo.to=this.$V.pane;
			setTimeout((function(){Event.fire(this,'xlv:ajax_loaded',memo);}).bind(this),1);
		},
		_dmReady:function(event){
			event.stop();
			this.removeObserve('xlv:pane_dm_ready','_dmReady',this.$V.pane);
			this.effect(this.$V.pane,this.$V._original_style);
		},
		getPane:function(){
			return this.$V.pane;
		},
		_paneBounds:function(pane){
		},
		instantize:function(pane){
			if(this.$P.onSite=='replace') {
				var panes=this.getObjects(this,'xlv.obj.pane');
				for(var i=0,n=panes.length;i<n;++i){
					xlv.sys.dispose(panes[i],true);
				}
				while(this.firstChild) this.removeChild(this.firstChild);
			}
			this.appendChild(this.$V.pane=pane);
			if(!pane.isDisplayNone()){
				var original_style={};
	    		['position','top','left','display','visibility'].
	    		each(function(k){original_style[k]=pane.style[k];});
	    		pane.style.visibility='hidden';
				xlv.sys.initialize(pane);
				if(pane.__dm_ready) {
					this.$V._original_style=original_style;
					this.addEventHandler('xlv:pane_dm_ready','_dmReady',pane);
				}else this.effect(pane,original_style);
			}else {
				xlv.sys.initialize(pane);
				this._paneBounds(pane);
				this.loaded();
			}
		},
		effect:function(pane,original_style){
			this._paneBounds(pane);
			var dim=Element.getDimensions(pane);
			var this_overflow=Element.getStyle(this,'overflow');
			if(!original_style){
				original_style={};
	    		['position','top','left','display','visibility'].
	    		each(function(k){original_style[k]=pane.style[k];});
			}
			pane.style.visibility='hidden';
			var effect={element:pane};
			var pane_in=this.$P.paneIn;
			if(!Object.isString(this.$P.paneIn)){
				 pane_in=this.$P.paneIn.paneIn;
				 effect = Object.extend({},this.$P.paneIn.effect);
				 effect.element=pane;
			}
			this.style.overflow='hidden';
			var pstyle=pane.style;
			if(pane_in=='center'){
				effect.style={left:original_style.left,top:original_style.top,width:dim.width,height:dim.height};
				pstyle.left=(dim.width/2-24)+'px';
				pstyle.top=(dim.height/2-24)+'px';
				pstyle.width='24px';
				pstyle.height='24px';
			}else{
				if(pane_in=='left'){
					effect.style={left:original_style.left};
					pstyle.left=-dim.width+'px';
				}
				if(pane_in=='top'){
					effect.style={top:original_style.top};
					pstyle.top=-dim.height+'px';
				}
				if(pane_in=='right'){
					effect.style={left:original_style.left};
					pstyle.left=dim.width+'px';
				}
				if(pane_in=='bottom'){
					effect.style={top:original_style.top};
					pstyle.top=dim.height+'px';
				}
				if(pane_in=='left-top'||pane_in=='top-left'){
					effect.style={left:original_style.left,top:original_style.top};
					pstyle.left=-dim.width+'px';
					pstyle.top=-dim.height+'px';
				}
				if(pane_in=='top-right'||pane_in=='right-top'){
					effect.style={left:original_style.left,top:original_style.top};
					pstyle.left=dim.width+'px';
					pstyle.top=-dim.height+'px';
				}
				if(pane_in=='right-bottom'||pane_in=='bottom-right'){
					effect.style={left:original_style.left,top:original_style.top};
					pstyle.left=dim.width+'px';
					pstyle.top=dim.height+'px';
				}
				if(pane_in=='bottom-left'||pane_in=='left-bottom'){
					effect.style={left:original_style.left,top:original_style.top};
					pstyle.left=-dim.width+'px';
					pstyle.top=dim.height+'px';
				}
			}
			effect.finished=(function(){
				this.style.overflow=this_overflow;
				if(Prototype.Browser.IE){
					if(dim.width>0)pane.style.width=dim.width+'px';
				}
				this.loaded();
			}).bind(this);
			pane.style.visibility='visible';
			xlv.util.styleEffect(effect);
		},
		ajax_response:function(aT,aJ){
			if(this.$V.loading){
				this.$V.loading.parentNode.removeChild(this.$V.loading);
				this.$V.loading=null;
			}
			var div=document.createElement('div');
			div.innerHTML=aT.responseText;
			var pane=xlv.util.findChild(div,{xlvobject:/xlv.obj.borderLayout|xlv.obj.pane/},false,false);
			if(pane){
				xlv.sys.extend(pane,this.$V.properties,this.$V.method);
			}else{
				pane=div;
				pane.setAttribute('xlvobject','xlv.obj.pane');
				xlv.sys.extend(pane,this.$V.properties,this.$V.method);
				//pane.setGlow({enable:true});
				//pane.setBorder({enable:true});
			}
			this.instantize(pane);
			this.onSuccess();
		},		
		/**be overwrite**/
		onSuccess:function(){}
	}
};

